import json
import pyecharts as pye
f_jp = open("./日本.txt","r",encoding="UTF-8")
f_us = open("./美国.txt","r",encoding="UTF-8")
f_in = open("./印度.txt","r",encoding="UTF-8")
#日本
jp_data = f_jp.read()
jp_data = jp_data.replace(jp_data[0:26],"")#去头
jp_data = jp_data.replace(");","")#去尾
jp_dict = json.loads(jp_data)
jp_updateDate = jp_dict["data"][0]["trend"]["updateDate"][:314]#获取日期数据，放到X轴
jp_quezheng = jp_dict["data"][0]["trend"]["list"][0]["data"][:314]
#美国
us_data = f_us.read()
us_data = us_data.replace(us_data[0:26],"")#去头
us_data = us_data.replace(");","")#去尾
us_dict = json.loads(us_data)
us_updateDate = us_dict["data"][0]["trend"]["updateDate"][:314]#获取日期数据，放到X轴
us_quezheng = us_dict["data"][0]["trend"]["list"][0]["data"][:314]
#印度
in_data = f_in.read()
in_data = in_data.replace(in_data[0:26],"")#去头
in_data = in_data.replace(");","")#去尾
in_dict = json.loads(in_data)
in_updateDate = in_dict["data"][0]["trend"]["updateDate"][:314]#获取日期数据，放到X轴
in_quezheng = in_dict["data"][0]["trend"]["list"][0]["data"][:314]
print(in_quezheng)
line = pye.charts.Line()
line.set_global_opts(
    pye.options.TitleOpts(
        title="美日印三国2020年疫情确证数据",
        pos_left="center",
        pos_bottom="1%"
        ))
line.add_xaxis(us_updateDate)
line.add_yaxis("美国确证数据",us_quezheng,label_opts=False)#添加Y轴数据
line.add_yaxis("日本确证数据",jp_quezheng,label_opts=False)#添加Y轴数据
line.add_yaxis("印度确证数据",in_quezheng,label_opts=False)#添加Y轴数据
line.render("美日印三国数据.html")
f_in.close()
f_jp.close()
f_us.close()